<template>
    <el-card>
        <el-form :inline="true">
            <el-form-item label="一级分类" width="200px">
                <el-select v-model="cagetoryStore.c1Id" @change="handle" :disabled="scenne == 0 ? false : true">
                    <el-option v-for="(c1) in cagetoryStore.c1Arr" :key="c1.id" :label="c1.name"
                        :value="c1.id"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="二级分类">
                <el-select v-model="cagetoryStore.c2Id" @change="handle1" :disabled="scenne == 0 ? false : true">
                    <el-option v-for="c2 in cagetoryStore.c2Arr" :key="c2.id" :label="c2.name"
                        :value="c2.id"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="三级分类">
                <el-select v-model="cagetoryStore.c3Id" :disabled="scenne == 0 ? false : true">
                    <el-option v-for="c3 in cagetoryStore.c3Arr" :key="c3.id" :label="c3.name"
                        :value="c3.id"></el-option>
                </el-select>
            </el-form-item>

        </el-form>
    </el-card>
</template>

<script setup lang="ts">
import { onMounted } from "vue"
// 获取分类的仓库
import useCagetoryStore from "@/store/modules/cagetory"
const cagetoryStore = useCagetoryStore()

onMounted(() => {
    getC1()
})

// 获取一级分类数据的方法
const getC1 = () => {

    cagetoryStore.getC1()
}
// 获取二级分类数据的方法
const handle = () => {
    // 需要注意的是，当我们改变下拉框中的值时。需要清空后买下拉框的值
    cagetoryStore.c2Id = '',
        cagetoryStore.c3Arr = [],
        cagetoryStore.c3Id = '',
        cagetoryStore.getC2()
}
// 获取三级分类数据的方法
const handle1 = () => {
    // 清理三级分类的id
    cagetoryStore.c3Id = '',
        cagetoryStore.getC3()
}

// 接受父组件传来的数据
defineProps(['scenne'])

</script>
<style lang="scss" scoped>
.el-select {
    width: 220px;
}
</style>